1
|
|
|
/** |
2
|
|
|
* Service authenticator |
3
|
|
|
* |
4
|
|
|
* @since 1.0.0 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
4 |
|
const StatusType = require('../repository/StatusType'); |
8
|
4 |
|
const DeviceType = require('../repository/DeviceType'); |
9
|
|
|
|
10
|
4 |
|
const menus = [ |
11
|
|
|
{ viewName: 'StatusList', title: '공지사항 관리', url: '/' }, |
12
|
|
|
{ viewName: 'SettingList', title: '설정', url: '/settings' }, |
13
|
|
|
]; |
14
|
|
|
|
15
|
|
|
function view(request, reply, childViewName, context) { |
16
|
2 |
|
const ctx = context || {}; |
17
|
|
|
ctx.viewName = childViewName; |
18
|
2 |
|
if (request.auth) { |
19
|
|
|
ctx.auth = { |
20
|
|
|
isAuthenticated: request.auth.isAuthenticated, |
21
|
|
|
username: request.auth.credentials ? request.auth.credentials.username : undefined, |
22
|
|
|
}; |
23
|
|
|
} |
24
|
|
|
ctx.menus = menus; |
25
|
|
|
ctx.state = `window.state = ${JSON.stringify(ctx)}`; |
26
|
|
|
return reply.view('Layout', ctx); |
27
|
|
|
} |
28
|
|
|
|
29
|
4 |
|
module.exports = [ |
30
|
|
|
{ |
31
|
|
|
method: 'GET', |
32
|
|
|
path: '/', |
33
|
|
|
handler: (request, reply) => Promise.all([StatusType.find(), DeviceType.find()]) |
34
|
|
|
.then(([statusTypes, deviceTypes]) => view(request, reply, 'StatusList', { statusTypes, deviceTypes })) |
35
|
|
|
.catch(error => reply(error)), |
36
|
|
|
}, |
37
|
|
|
{ |
38
|
|
|
method: 'GET', |
39
|
|
|
path: '/settings', |
40
|
|
|
handler: (request, reply) => view(request, reply, 'SettingList', {}), |
41
|
|
|
}, |
42
|
|
|
{ |
43
|
|
|
method: 'GET', |
44
|
|
|
path: '/login', |
45
|
|
|
handler: (request, reply) => { |
46
|
2 |
|
if (request.auth.isAuthenticated) { |
47
|
|
|
return reply.redirect('/'); |
48
|
|
|
} |
49
|
|
|
return view(request, reply, 'Login'); |
50
|
|
|
}, |
51
|
|
|
config: { |
52
|
|
|
auth: { |
53
|
|
|
mode: 'try', |
54
|
|
|
}, |
55
|
|
|
}, |
56
|
|
|
}, |
57
|
|
|
{ |
58
|
|
|
method: 'GET', |
59
|
|
|
path: '/logout', |
60
|
|
|
handler: (request, reply) => reply.redirect('/login').unstate('token'), |
61
|
|
|
}, |
62
|
|
|
{ |
63
|
|
|
method: 'GET', |
64
|
|
|
path: '/change-password', |
65
|
|
|
handler: (request, reply) => view(request, reply, 'ChangePassword'), |
66
|
|
|
}, |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
|